import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
import numpy as np
import json
from datetime import datetime
from urllib.request import urlopen
import plotly.io as pio
pio.renderers.default = "browser"
#pio.renderers.default = "svg"
#filename = 'data/eq_data_30_day_m1.json'
#with open(filename) as f:
#    all_eq_data = json.load(f)
#all_eq_dicts = all_eq_data['features']
#mags, lons, lats = [], [], []
#for eq_dict in all_eq_dicts:
#    mag = eq_dict['properties']['mag']
#    lon = eq_dict['geometry']['coordinates'][0]
#    lat = eq_dict['geometry']['coordinates'][1]
#    mags.append(mag)
#    lons.append(lon)
#    lats.append(lat)
#print(mags[:10])
#print(lons[:5])
#print(lats[:5])
#data = pd.read_csv(filename)
#print(data.head())
#print(data.columns)
#print(data['title'])
#print(data[['title', 'mag']])
#print(data['mag'].max())
#print(data['mag'].min())
#print(data['mag'].mean())
#print(data['mag'].value_counts())
#print(data['mag'].describe())
#print(data['mag'].value_counts().sort_index())
#print(data['mag'].value_counts().sort_index(ascending=False))
#print(data['mag'].value_counts().sort_index(ascending=True))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10))
#print(data['mag'].value_counts().sort_index(ascending=False).tail(10))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='bar'))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='barh'))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='pie'))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='line'))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='area'))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='bar',color='red'))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='bar',color='red',title='Top 10 Magnitudes'))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='bar',color='red',title='Top 10 Magnitudes',xlabel='Magnitude',ylabel='Frequency'))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='bar',color='red',title='Top 10 Magnitudes',xlabel='Magnitude',ylabel='Frequency',grid=True))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='bar',color='red',title='Top 10 Magnitudes',xlabel='Magnitude',ylabel='Frequency',grid=True,figsize=(10,5)))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='bar',color='red',title='Top 10 Magnitudes',xlabel='Magnitude',ylabel='Frequency',grid=True,figsize=(10,5),fontsize=10))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='bar',color='red',title='Top 10 Magnitudes',xlabel='Magnitude',ylabel='Frequency',grid=True,figsize=(10,5),fontsize=10,legend=True))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='bar',color='red',title='Top 10 Magnitudes',xlabel='Magnitude',ylabel='Frequency',grid=True,figsize=(10,5),fontsize=10,legend=True,rot=45))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='bar',color='red',title='Top 10 Magnitudes',xlabel='Magnitude',ylabel='Frequency',grid=True,figsize=(10,5),fontsize=10,legend=True,rot=45,alpha=0.5))
#print(data['mag'].value_counts().sort_index(ascending=False).head(10).plot(kind='bar',color='red',title='Top 10 Magnitudes',xlabel='Magnitude',ylabel='Frequency',grid=True,figsize=(10,5),fontsize=10,legend=True,rot=45,alpha=0.5,width=0.5))

#filename = 'data/eq_data_1_day_m1.json'
#with open(filename) as f:
#    all_eq_data = json.load(f)
#all_eq_dicts = all_eq_data['features']
#mags, lons, lats, hover_texts = [], [], [], []
#for eq_dict in all_eq_dicts:
#    mag = eq_dict['properties']['mag']
#    lon = eq_dict['geometry']['coordinates'][0]
#    lat = eq_dict['geometry']['coordinates'][1]
#    title = eq_dict['properties']['title']
#    mags.append(mag)
#    lons.append(lon)
#    lats.append(lat)
#    hover_texts.append(title)
#print(mags[:10])
#print(lons[:5])
#print(lats[:5])
#print(hover_texts[:5])
#print(len(mags))
#print(len(lons))
#print(len(lats))
#print(len(hover_texts))
#print(len(all_eq_dicts))
#print(all_eq_dicts[0])
#print(all_eq_dicts[0]['properties'])
#print(all_eq_dicts[0]['properties']['mag'])
#print(all_eq_dicts[0]['geometry'])
#print(all_eq_dicts[0]['geometry']['coordinates'])
#print(all_eq_dicts[0]['geometry']['coordinates'][0])
#print(all_eq_dicts[0]['geometry']['coordinates'][1])
#print(all_eq_dicts[0]['properties']['title'])

#data = pd.read_csv('data/sitka_weather_2018_simple.csv')
#print(data.head())
#print(data.columns)
#print(data['DATE'])
#print(data['DATE'].head())
#print(data['DATE'].head().values)
#print(data['DATE'].head().values[0])
#print(data['DATE'].head().values[0].split('-'))
#print(data['DATE'].head().values[0].split('-')[0])
#print(data['DATE'].head().values[0].split('-')[1])
#print(data['DATE'].head().values[0].split('-')[2])
#print(data['DATE'].head().values[0].split('-')[0] + '-' + data['DATE'].head().values[0].split('-')[1] + '-' + data['DATE'].head().values[0].split('-')[2])
#print(data['DATE'].head().values[0].split('-')[0] + '-' + data['DATE'].head().values[0].split('-')[1] + '-' + data['DATE'].head().values[0].split('-')[2][:2])
#print(data['DATE'].head().values[0].split('-')[0] + '-' + data['DATE'].head().values[0].split('-')[1] + '-' + data['DATE'].head().values[0].split('-')[2][:2] + ' ' + data['DATE'].head().values[0].split('-')[2][3:])
#print(data['DATE'].head().values[0].split('-')[0] + '-' + data['DATE'].head().values[0].split('-')[1] + '-' + data['DATE'].head().values[0].split('-')[2][:2] +' ' + data['DATE'].head().values[0].split('-')[2][3:])
#print(data['DATE'].head().values[0].split('-')[0] + '-' + data['DATE'].head().values[0].split('-')[1] + '-' + data['DATE'].head().values[0].split('-')[2][:2] +''+ data['DATE'].head().values[0].split('-')[2][3:])

#filename = 'data/sitka_weather_2018_simple.csv'
#with open(filename) as f:
#    reader = csv.reader(f)
#    header_row = next(reader)
#    print(header_row)
#    for index, column_header in enumerate(header_row):
#        print(index, column_header)
#    for row in reader:
#        print(row)

#filename = 'data/sitka_weather_2018_simple.csv'
#with open(filename) as f:
#    reader = csv.reader(f)
#    header_row = next(reader)
#    print(header_row)
#    for index, column_header in enumerate(header_row):
#        print(index, column_header)    
#    highs = []
#    for row in reader:
#        high = int(row[5])
#        highs.append(high) 
#    print(highs)
#    print(len(highs))

#filename = 'data/sitka_weather_2018_simple.csv'
#with open(filename) as f:
#    reader = csv.reader(f)
#    header_row = next(reader)
#    print(header_row)
#    for index, column_header in enumerate(header_row):